package com.yuexun.beilunpatient.ui.login.presenter.impl;

import com.yuexun.beilunpatient.ui.bean.BaseListEntity;
import com.yuexun.beilunpatient.ui.login.bean.LoginBean;
import com.yuexun.beilunpatient.ui.login.bean.SmsBean;
import com.yuexun.beilunpatient.ui.login.model.ILoginModel;
import com.yuexun.beilunpatient.ui.login.presenter.IChangePasswordPresenter;
import com.yuexun.beilunpatient.ui.login.ui.view.IChangePasswordView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenss on 2018/9/25.
 */
public class ChangePasswordPresenter implements IChangePasswordPresenter {

    private IChangePasswordView view;
    private ILoginModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public ChangePasswordPresenter(ILoginModel model, IChangePasswordView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void resetPasswordOfSms(Map<String, String> praise) {
        model.resetPasswordOfSms(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseListEntity<SmsBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("获取验证码失败");
                    }

                    @Override
                    public void onNext(BaseListEntity<SmsBean> entity) {
                        view.resetPasswordOfSms(entity);
                    }
                });
    }

    @Override
    public void resetPassword(Map<String, String> praise) {
        model.resetPassword(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseListEntity<LoginBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("重置密码失败");
                    }

                    @Override
                    public void onNext(BaseListEntity<LoginBean> entity) {
                        view.resetPassword(entity);
                    }
                });
    }
}
